#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;

 struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode() : val(0), left(nullptr), right(nullptr) {}
     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 };
int maxDepth(TreeNode* root) {
    queue<TreeNode*> q;
    if(root)
        q.push(root);
    int count = 0;
    while(q.size())
    {
        int size = q.size();
        count++;
        for(int i=0;i<size;i++)
        {
            if(q.front()->left)
                q.push(q.front()->left);
            if(q.front()->right)
                q.push(q.front()->right);
            q.pop();
        }
    }
    return count;
}
int main()
{
    TreeNode* root = new TreeNode(3);
    TreeNode* cur = root;
    cur->left = new TreeNode(9);
    cur = cur->left;
    cur->right = new TreeNode(20);
    cur = cur->right;
    cur->left = new TreeNode(15);
    cur=root;
    cur->right = new TreeNode(7);
    cur = cur->right;
    cur->left = new TreeNode(7);
    cur->right = new TreeNode(15);
    cur = cur->right;
    cur-> right = new TreeNode(15);
    cur = cur->right;
    cur->left = new TreeNode(15);
    int deep = maxDepth(root);
    cout << deep;
    return 0;
}